<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="__PUBLIC__/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="__PUBLIC__/font-awesome/css/font-awesome.min.css" media="all" />
    <link rel="stylesheet" href="__CSS__/admin.css" media="all">
</head>
<style>
    .layui-upload-img {
        width: 100px;
    !important;
    }

    .addclassify {
        display: inline-block;
        width: 40px;
        height: 40px;
        border: 1px solid #666;
        line-height: 40px;
        border-radius: 40px;
        text-align: center;
        cursor: pointer;
    }

    #right {
        width: 200px;
        height: 300px;
        border: 1px solid #777;
        overflow-y: scroll;
    }

    .btns span {
        margin: 5px 10px;
    }

    .shi {
        text-align: center;
        font-size: 16px;
        margin: 10px 0;
    }

    .activity {
        background: #1E9FFF;
        color: white;
    }

    .tabs {
        /*border: 1px solid #868686;*/
        padding: 5px 40px;
    }
</style>

<body>
<div style="margin-top: 20px;">
</div>

<div id="classifybox">
    <div class="layui-form-item classifychild">
        <input type="hidden" value="{$goods.goods_id}" name="goods_id">
        <label class="layui-form-label">售卖时间</label>
        <div class="layui-input-inline layui-input" style="width: 500px;line-height:38px;">
            {$goods.starttime|date="Y-m-d",###}~{$goods.endtime|date="Y-m-d",###}
        </div>
    </div>
    {volist name="specs" id="vo"}
    <div class="layui-form-item classifychild">
        <label class="layui-form-label">套餐规格</label>
        <div class="layui-input-inline person" style="width: 500px">
            <div class="layui-input-inline" style="width: 400px;padding-bottom: 15px">
                <input name="specs_name" readonly value="{$vo.specs_name}"  placeholder="规格名称" autocomplete="off" class="layui-input" type="text" lay-key="1">
            </div>
        </div>

        <div class="layui-form-item childs">
            <label class="layui-form-label">&nbsp;</label>
            <div class="layui-input-inline person" style="width: 600px">
                <table class="layui-table">
                    <thead>
                    <tr>
                        <th>出行类型</th>
                        <th>默认价格</th>
                        <th>数量</th>
                        <th>最低下单数</th>
                        <th>出行日期</th>
                        <th>操作</th>
                    </tr>
                    </thead>
                    <tbody class="personchild">

                    {volist name="vo['person']" id="vo1"}
                    <tr>
                        <td>
                            <input name="person_name" readonly value="{$vo1.person_name}" style="width:60px;"  placeholder="出行人群" autocomplete="off" class="layui-input layui-col-xs5" type="text" lay-key="2">
                        </td>
                        <td>
                            <input name="person_price" readonly value="{$vo1.person_price}" style="width:60px;"  placeholder="价格" autocomplete="off" class="layui-input layui-col-xs5" type="number" lay-key="2">
                        </td>
                        <td>
                            <input name="person_num" readonly value="{$vo1.person_num}" style="width:50px;" placeholder="数量" autocomplete="off" class="layui-input layui-col-xs5" type="number" lay-key="2">
                        </td>
                        <td>
                            <input name="minorder_num" readonly value="{$vo1.minorder_num}" style="width:50px;"  placeholder="最低下单数" autocomplete="off" class="layui-input layui-col-xs5" type="number" lay-key="2">
                        </td>
                        <td>
                            <input name="time" readonly value="{$vo1.time}" autocomplete="off" style="width:90px;" class="layui-input layui-col-xs5" type="text" lay-key="2">
                        </td>
                        <td style="width:120px;">
                            <span class="layui-btn layui-btn-normal layui-btn-sm modifyPerson" style="margin-top: 4px;margin-left:0;">修改</span>
                            <span class="layui-btn layui-btn-danger layui-btn-sm delPerson" style="margin-top: 4px;margin-left:0;"data-id="{$vo1.id}">删除</span>
                            <span class="layui-btn layui-btn-warning layui-btn-sm submitPerson" style="margin-top: 4px;margin-left:0;display: none;" data-id="{$vo1.id}">提交</span>
                            <span class="layui-btn layui-btn-primary layui-btn-sm cancelPerson" style="margin-top: 4px;margin-left:0;display: none;">取消</span>
                        </td>
                    </tr>
                    {/volist}

                    </tbody>
                </table>

            </div>
        </div>

    </div>
    {/volist}
</div>

<script src="__PUBLIC__/layui/layui.js"></script>
<script src="__PUBLIC__/jquery/jquery.min.js"></script>
<script>
    var message;
    layui.config({
        base: '__JS__/',
        version: '1.0.1'
    }).use(['app', 'message'], function() {
        var app = layui.app,
            $ = layui.jquery,
            layer = layui.layer;
        //将message设置为全局以便子页面调用
        message = layui.message;
        //主入口
        app.set({
            type: 'iframe'
        }).init();
    });
</script>
<script>
    layui.use(['layer', 'laydate', 'form'], function() {

        var layer = layui.layer,
            $ = layui.jquery,
            laydate = layui.laydate,
            form = layui.form;

    });
    var is_prompt = true;
        $(".modifyPerson").on("click",function(){
            var inputs = $(this).parent().parent().find("input[name!=time]");
            $(this).parent().parent().css("background","#ddd");
            $(this).hide();
            $(this).next().hide();
            $(this).next().next().show();
            $(this).next().next().next().show();
            $.each(inputs,function(i,v){
                $(v).removeAttr("readonly");
            })
        })

        function ajaxDelProson(_that,person_id)
        {
            $.post("/admin/goods/delSinglePerson",{person_id:person_id},function(data){
                layer.msg(data.msg);
                if(data.code==200){
                    _that.parent().parent().remove();
                }
            },"json")
        }



        $(".delPerson").on("click",function(){
            var that = $(this);
            layer.confirm('您确定删除吗?', {btn: ['确定', '取消'], title: "提示"}, function () {
                var person_id = that.attr("data-id");
                ajaxDelProson(that,person_id);
            });
        })

        $(".cancelPerson").on("click",function(){
            $(this).hide();
            $(this).prev().hide();
            $(this).prev().prev().show();
            $(this).prev().prev().prev().show();
            $(this).parent().parent().css("background","#fff");
            $(this).parent().parent().find("input[name!=time]").attr("readonly","readonly");
        })

        $(".submitPerson").on("click",function(){
            var goods_id = $("input[name=goods_id]").val();
            var person_id = $(this).attr("data-id");
            var parent = $(this).parent().parent();
            var person_name = parent.find("input[name=person_name]").val();
            var person_price = parent.find("input[name=person_price]").val();
            var person_num = parent.find("input[name=person_num]").val();
            var minorder_num = parent.find("input[name=minorder_num]").val();
            var _that = $(this);
            if(person_name=="" || person_name==undefined || person_name==0){
                layer.msg("出行类型不能为空");
            }
            if(person_price=="" || person_price==undefined || person_name==0){
                layer.msg("默认价格不能为空");
            }
            if(person_num=="" || person_num==undefined || person_name==0){
                layer.msg("数量不能为空");
            }
            if(minorder_num=="" || minorder_num==undefined || person_name==0){
                layer.msg("最低下单不能为空");
            }

            var postdata = {
                'goods_id':goods_id,
                'person_id':person_id,
                'person_name':person_name,
                'person_num':person_num,
                'person_price':person_price,
                'minorder_num':minorder_num,
            };
            console.log(postdata);
            $.post("/admin/goods/modifySinglePerson",postdata,function(data){
                if(data.code==200){
                    layer.msg(data.msg);
                    _that.prev().prev().show();
                    _that.prev().show();
                    _that.hide();
                    _that.next().hide();
                    _that.parent().parent().css("background","#fff");
                    _that.parent().parent().find("input[name!=time]").attr("readonly","readonly");
                }else{
                    layer.msg("修改失败，请刷新后重试");
                }
            },"json")


        })

</script>
</body>

</html>